import Vue from 'vue'
import Router from 'vue-router'

const NoFound = r => require.ensure([], () => r(require('../pages/NotFound.vue')), 'group-none')
const Login = r => require.ensure([], () => r(require('../pages/Login.vue')), 'group-login')

const DashBoard = r => require.ensure([], () => r(require('../pages/home/dashboard/index.vue')), 'group-dashboard')
const UserProfile = r => require.ensure([], () => r(require('../pages/home/user/index.vue')), 'group-user-profile')

const Home = r => require.ensure([], () => r(require('../pages/home/index.vue')), 'group-home')

const User = r => require.ensure([], () => r(require('../pages/admin/user/index.vue')), 'group-user')
const Role = r => require.ensure([], () => r(require('../pages/admin/role/index.vue')), 'group-role')
const Menu = r => require.ensure([], () => r(require('../pages/admin/menu/index.vue')), 'group-menu')
const Department = r => require.ensure([], () => r(require('../pages/admin/department/index.vue')), 'group-dept')
// const Dictionary = r => require.ensure([], () => r(require('../pages/admin/dictionary/TagsView.vue')), 'group-gate')
// const GroupType = r => require.ensure([], () => r(require('../pages/admin/groupType/TagsView.vue')), 'group-group')
// const File = r => require.ensure([], () => r(require('../pages/admin/file/TagsView.vue')), 'group-file')

const Log = r => require.ensure([], () => r(require('../pages/monitor/Log.vue')), 'group-monitor')
const LoginLog = r => require.ensure([], () => r(require('../pages/monitor/LoginLog.vue')), 'group-monitor')
// const Session = r => require.ensure([], () => r(require('../pages/monitor/Session.vue')), 'group-monitor')
// const Redis = r => require.ensure([], () => r(require('../pages/monitor/Redis.vue')), 'group-monitor-redis')
const Client = r => require.ensure([], () => r(require('../pages/monitor/Client.vue')), 'group-monitor-cliten')

Vue.use(Router)

export const constantRouterMap = [
  {
    path: '/login',
    component: Login,
    hidden: true // 不显示在导航中
  },
  {
    path: '/',
    component: Home,
    redirect: '/dashboard',
    icon: 'fa-home',
    name: '首页',
    children: [
      { name: '控制面板', path: '/dashboard', component: DashBoard, affix: true },
      { name: '用户信息', path: '/user', component: UserProfile }
    ]
  },
  {
    path: '/404',
    component: NoFound,
    hidden: true
  }
]

export default new Router({
  // scrollBehavior: () => ({
  //   y: 0
  // }),
  routes: constantRouterMap
})

export const asyncRouterMap = [

  {
    // ---- 权限管理
    path: '/manager',
    component: Home,
    name: '系统管理',
    icon: 'fa-cog',
    authority: 'system:manager',
    children: [
      { path: '/manager/user', component: User, name: '用户管理', authority: 'admin:list' },
      { path: '/manager/menu', component: Menu, name: '菜单管理', authority: 'menu:list' },
      { path: '/manager/role', component: Role, name: '角色管理', authority: 'role:list' },
      { path: '/manager/dept', component: Department, name: '部门管理', authority: 'dept:list' }
    ]
  },
  // --- 系统监控
  {
    path: '/admin/monitor',
    component: Home,
    name: '系统监控',
    icon: 'fa-eye',
    authority: 'system:monitor',
    children: [
      { path: '/monitor/log', component: Log, name: '系统日志', authority: 'log:list' },
      { path: '/monitor/log/login', component: LoginLog, name: '登录日志' },
      // { path: '/monitor/session', component: Session, name: '在线用户', authority: 'session:list' },
      // { path: '/monitor/redis', component: Redis, name: 'Redis监控', authority: 'redis:monitor' },
      { path: '/monitor/client', component: Client, name: '客户端管理', authority: 'client:list' }
    ]
  },
  {
    path: '*',
    component: NoFound,
    hidden: true // 不显示在导航中
  }
]
